<template>
  <div class="CeremonyHall  h100" v-loading="loading">
    <div class="PageContent">
      <el-form :model="ruleForm" :inline="true" ref="ruleForm" label-width="80px" class="PageItem margintop20">
        <el-row :gutter="5" class="fileSearch">
          <el-col :span="8">
            <el-form-item label="火化日期:">
              <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.appointmentDateStart"
                              format="yyyy-MM-dd" :picker-options="pickerOptions"></el-date-picker>
              -
              <el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.appointmentDateEnd"
                              format="yyyy-MM-dd" :picker-options="pickerOptions"></el-date-picker>
            </el-form-item>
            <el-form-item label="火化类型" prop="cremationTypeCode">
              <el-select
                v-model="ruleForm.cremationTypeCode"
                clearable
                filterable
                placeholder="请选择火化类型"
                class="w150"
              >
                <el-option label="全部" value=""></el-option>
                <el-option
                  v-for="item in dictionary.cremation_type"
                  :key="item.dataCode"
                  :label="item.dataText"
                  :value="item.dataCode"
                  :disabled="item.disableState"
                />
              </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="逝者姓名:" prop="deadName">
              <el-input v-model="ruleForm.deadName" clearable></el-input>
            </el-form-item>
            <el-form-item label="区域:" prop="areaCode">
            <el-select
              v-model="ruleForm.areaCode"
              onkeydown="return (event.keyCode!=8)"
              placeholder="请选择"
            >
              <el-option label="全部" value></el-option>
              <el-option label="外地" :value="-1"></el-option>
              <el-option
                v-for="item in areaDictionary"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="证件号码:" prop="certificateNo">
              <el-input v-model="ruleForm.certificateNo" clearable></el-input>
            </el-form-item>
             <el-form-item>
            <el-button type="primary"  v-if="btnRight.btnCremationRecordSearch" @click="onSubmit('search')">
              查询
            </el-button>
            <el-button icon="el-icon-refresh" v-if="btnRight.btnCremationRecordReset"  @click="resetQuery">重置</el-button>
            <el-button type="primary"  plain v-if="btnRight.btnCremationRecordExport" @click="openExecl">
              导出Excel
            </el-button>
          </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="遗体状态" prop="remainsStateCode">
            <el-select
              v-model="ruleForm.remainsStateCode"
              clearable
              filterable
              placeholder="请选择遗体状态"
              class="w150"
            >
              <el-option label="全部" value=""></el-option>
              <el-option
                v-for="item in dictionary.remains_state"
                :key="item.dataCode"
                :label="item.dataText"
                :value="item.dataCode"
                :disabled="item.disableState"
              />
            </el-select>
          </el-form-item>
             <el-form-item>
               <el-button type="primary" @click="addNewDead">添加</el-button>
               <el-button type="warning" @click="templateIn()">导出模板</el-button>
               <el-button plain @click="$refs.file.click()">导入</el-button>
               <input type="file" style="display:none" accept=".xls,.xlsx" ref="file" @change="fileChange" />
            <!-- <el-button type="danger" @click="deleteDead">删除</el-button> -->
          </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="6">
        </el-row>
        <el-table
          :data="tableData"
          border
          v-loading="tableLoading"
          :header-cell-style="{background:'rgb(246,247,251)',color:'#606266'}"
          stripe
          @selection-change="handleSelectionChange"
          :height="tableHeight">
          <!-- <el-table-column
            type="selection"
            fixed="left"
            width="55">
          </el-table-column> -->
          <el-table-column sortable align='center' prop="businessCode" label="业务编码" width="200">
          </el-table-column>
          <el-table-column
            prop="appointmentDate"
            align='center'
            label="火化日期"
            width="200">
          </el-table-column>
          <el-table-column
            prop="arrivedTime"
            align='center'
            label="到馆时间"
            width="200">
          </el-table-column>
          <el-table-column
            prop="deadName"
            align='center'
            label="逝者姓名"
            width="150">
          </el-table-column>
          <el-table-column
            prop="deadGender"
            align='center'
            label="逝者性别"
            width="120">
          </el-table-column>
          <el-table-column
            prop="deadAge"
            align='center'
            label="年龄"
            width="100">
          </el-table-column>
          <el-table-column
            prop="cremationType"
            align='center'
            label="火化类型"
            width="150">
          </el-table-column>
          <el-table-column
            prop="certificateType"
            align='center'
            label="逝者证件类型"
            width="150">
          </el-table-column>
          <el-table-column
            prop="certificateNo"
            align='center'
            label="逝者证件号码"
            width="200">
          </el-table-column>
          <el-table-column
            prop="householdRegistrationPlace"
            align='center'
            label="户口所在地"
            width="120">
          </el-table-column>
          <el-table-column
            prop="beforeDeathAddress"
            align='center'
            label="生前地址"
            width="150">
          </el-table-column>
          <el-table-column
            prop="deathDate"
            align='center'
            label="死亡时间"
            width="150">
          </el-table-column>
          <el-table-column
            prop="deathCause"
            align='center'
            label="死亡原因"
            width="150">
          </el-table-column>
          <el-table-column
            prop="contact"
            align='center'
            label="联系人"
            width="100">
          </el-table-column>
          <el-table-column
            prop="contactPhone"
            align='center'
            label="联系电话"
            width="200">
          </el-table-column>
          <el-table-column
            prop="relation"
            align='center'
            label="联系人与逝者关系"
            width="200">
          </el-table-column>
          <el-table-column
            prop="fullName"
            align="center"
            label="受理人"
            width="200">
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            label="操作"
            width="200">
            <template slot-scope="scope">
              <el-button size="mini" type="primary" @click="editDead(scope.row.businessCode)">编辑</el-button>
              <el-button size="mini"  type="primary" @click="loadCremationCertificate(scope.row.businessCode)">打印火化证明</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- <div style="text-align: center;
                    height: 0px;
                    line-height: 20px;
                    font-size: 18px;">
          显示{{ pager.total === 0 ? 0 : (Math.ceil(pager.total / pager.pageSize) > 1 ? ((pager.currentPage - 1) * pager.pageSize + 1) : (1)) }}到{{ pager.total === 0 ? 0 : ((Math.ceil(pager.total / pager.pageSize) === pager.currentPage) ? (pager.total) : (pager.currentPage * pager.pageSize)) }}条
        </div> -->
        <p style="text-align: right;margin-top: 20px;">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pager.currentPage"
            :page-size="pager.pageSize"
            :page-sizes="[10,20,30,50]"
            background
            layout="total,sizes,prev, pager, next, jumper"
            :total="pager.total">
          </el-pagination>
        </p>
      </el-form>
    </div>
    <home-dialog ref="homeDialog" :homeDialogVisible='homeDialogShow'></home-dialog>
    <el-dialog title="操作类型" v-dialogDrag class="print_dialog"  :visible.sync="printTypeVisible" @close="closeprintTypeDialog">
      <el-form ref='printTypeForm' :model="saveCertificate" :rules="saveCertificateRules">
        <div class="PageItem ">
        <el-row class="PageInfo"><i class="info-bar"></i>火化证明打印</el-row>
        <el-row :gutter="0"  class="paddingleft2">
          <el-form-item label="操作类型:"  prop="operationTypeCode"  class="marginright50">
            <el-select v-model="saveCertificate.operationTypeCode" @change="operationType(saveCertificate.operationTypeCode)" placeholder="请选择"  style="width: 200px;">
              <el-option
                  v-for="(item) in printTypes"
                  :key="item.label"
                  :label="item.label"
                  :value="item.value"/>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row :gutter="0"  class="paddingleft2">
        <el-form-item label="原因:" class="textarea"  :prop="saveCertificate.operationTypeCode!='1'?'operationCause':'operationCause1'">
          <el-input type="textarea" v-model="saveCertificate.operationCause" ></el-input>
        </el-form-item>
      </el-row>
      </div>
      <div class="PageItem ">
      <el-row class="PageInfo"><i class="info-bar"></i>打印历史记录</el-row>
      <el-table
        :data="printHistory"
        :header-cell-style="{background:'rgb(246,247,251)',color:'#606266'}"
        stripe
        border
        style="width: 100%;">
        <el-table-column align = 'center'  prop="operationTime"  label="打印日期"  width="200">
        </el-table-column>
        <el-table-column
          prop="operationType"
          align = 'center'
          label="操作类型"
          width="100">
        </el-table-column>
        <el-table-column
          prop="cremationNewNo"
          align = 'center'
          label="新火化证号"
          width="200">
        </el-table-column>
        <el-table-column
          prop="cremationOldNo"
          align = 'center'
          label="原火化证号"
          width="200">
        </el-table-column>
        <el-table-column
          prop="address"
          align = 'center'
          label="家庭住址">
        </el-table-column>
        <el-table-column
          prop="operationCause"
          align = 'center'
          label="原因"
          width="150">
        </el-table-column>
        <el-table-column
          prop="memberGender"
          align = 'center'
          label="家属性别"
          width="120">
        </el-table-column>

        <el-table-column
          prop="mobilePhone"
          align = 'center'
          label="家属手机号码"
          width="150">
        </el-table-column>
        <el-table-column
          prop="certificateType"
          align = 'center'
          label="家属证件类型"
          width="200">
        </el-table-column>
        <el-table-column
          prop="certificateNo"
          align = 'center'
          label="家属证件号码"
          width="200">
        </el-table-column>
        <el-table-column
          prop="memberRelation"
          align = 'center'
          label="与逝者关系"
          width="150">
        </el-table-column>
        <el-table-column
          prop="address"
          align = 'center'
          label="家庭住址">
        </el-table-column>
      </el-table>
      </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="printTypeVisible = false">取 消</el-button>
        <el-button type="primary" @click="startPrint('printTypeForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as Type from '@/api/service'
import download from "@/api/download"
import HomeDialog from "../dialog/HomeDialog";
import {provinceCityCounty} from "@/utils/provinceCityCounty";
import {getLodop} from "@/utils/lodopFuncs";
import {dataFormate, dataFormatetmd, dataFormatetmd1} from "@/utils/index";
import * as Cemetery from "@/api/cemetery/cemetery";
import axios from "axios";
export default {
  name: "CremationRecord",
  data() {
    return {
      printHistory:[],//打印历史
      printTypeVisible:false,//打印火化证类型
      homeDialogShow:false,
      loading: false,
      tableLoading:false,
      type: [],
      ruleForm: {
        "appointmentDateStart": "",
        "appointmentDateEnd": "",
        "deadName": "",
        "certificateNo": "",
        "remainsStateCode": "",
        "cremationTypeCode": "",
        "areaCode": "",
        "pageSize": 0,
        "currentPage": 0,
        "exportExcelFlag": 0
      },
       pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
      },
      pager: {
        "pageSize": 20,
        "total": 1,
        "currentPage": 1
      },
      tableData: [],
      dictionary: {},
      areaDictionary: [],
      deadInfo:{},//打印火花证查询的死者信息
      tableHeight: 0,
      // cremation: {//火化任务
      //       id: 0,
      //       cremationVersion: 0
      //     },
       printTypes:[
            {label:"发证",value: 1},
            {label:"重打",value: 2},
            {label:"补证",value: 3}
          ],
          saveCertificate:{ //要保存的数据
            "businessCode": "",
            "memberId": 0,
            "memberVersion": 0,
            "certificateTypeCode":"",
            "operationTypeCode": 1,
            "operationTime": "",
            "operationCause": "",
            "cremationOldNo": "",
            "cremationNewNo": ""
          },//打印保存的数据
          saveCertificateRules:{
            'operationTypeCode':[
              {
                required: true,
                message: "请选择操作类型",
                trigger: "change",
              }
            ],
            'operationCause':[
              {
                required: true,
                message: "请填原因",
                trigger: "blur",
              }
          ],
          'operationCause1':[
            {required: false, }
          ],
          },
      //按钮权限
      btnRight: {
        btnCremationRecordSearch: true, //查询
        btnCremationRecordReset:false,
        btnCremationRecordExport: true,//导出excel
      }
    }
  },
  components:{
    HomeDialog
  },
  //载入按钮
  mounted() {
    this.btnRight = this.$route.meta.buttons;
    //遍历属性赋值将true与false字符串转换成布尔型的值
    for (var key of Object.keys(this.btnRight)) {
      this.btnRight[key] = (this.btnRight[key] || this.btnRight[key] == "true") ? true : false;
    }

    this.areaDictionary = provinceCityCounty
      .find((item) => item.label === "山东省")
      .children.find((item) => item.label === "临沂市").children;


    this.$store.dispatch('user/getdictionary').then((res) => {     //获取字典数据
      this.dictionary = res;
      this.$set(this.dictionary, res)
    }).catch(() => console.log('promise catch err'))
    this.defaultValue();
    this.onSubmit()
    var that = this
    window.onresize = function () {
      var search = document.getElementsByClassName("fileSearch")[0].offsetHeight
      var dom = document.getElementsByClassName("PageContent")[0].offsetHeight
      that.tableHeight = dom - search - 190
    }
  },
  //注销window.onresize事件
  destroyed() {
    window.onresize = null;
  },
  updated() {
    this.$nextTick(() => {
      var dom = document.getElementsByClassName("PageContent")[0].offsetHeight
      var search = document.getElementsByClassName("fileSearch")[0].offsetHeight
      this.tableHeight = dom - search - 190
    })
  },
  methods: {
    fileChange(e) {
      console.log(this.$store.getters.token);
      e.target.files[0];
      let formData = new FormData();
      formData.append("file", e.target.files[0]);
      axios({
          method: "post",
          responseType:"blob",
          url: window.ROOT+"/api/excel/upload",
          data: formData,
          headers:{
            'token':this.$store.getters.token,
            'Content-Type': 'multipart/form-data'
          }
        },
      ).then(response => {
        this.$refs.file.value ='';
        const blob = new Blob([response.data],{ type: "application/vnd.ms-excel"});
        var file_name = "殡仪馆历史信息登记模板.xls"||this.getDateTime()+".xls";
        const linkNode = document.createElement('a')

        linkNode.download = file_name; //a标签的download属性规定下载文件的名称
        linkNode.style.display = 'none';
        linkNode.href = URL.createObjectURL(blob); //生成一个Blob URL
        document.body.appendChild(linkNode);
        linkNode.click();  //模拟在按钮上的一次鼠标单击

        URL.revokeObjectURL(linkNode.href); // 释放URL 对象
        document.body.removeChild(linkNode);

      });
    },


    getBase64(file) {
      return new Promise((resolve, reject) => {
        let reader = new FileReader();
        let fileResult = "";
        reader.readAsDataURL(file);
        //开始转
        reader.onload = function() {
          fileResult = reader.result;
        };
        //转 失败
        reader.onerror = function(error) {
          reject(error);
        };
        //转 结束  咱就 resolve 出去
        reader.onloadend = function() {
          resolve(fileResult);
        };
      });
    },

    //导出模板按钮
    templateIn() {
      //let message = "确认导出模板 ?";
      //this.$confirm(message, "提示", {})
      this.tableLoading=true
      //.then(() => {
      // 查询火化记录的接口
      download.exportExcel(Cemetery["templateIng"], null, "历史信息模板_" + download.getDateTime() + ".xlsx").then(res=>{
        if(res==='成功'){
          this.tableLoading=false
        }else{
          this.tableLoading=false
          this.$message.error("导出失败")
        }
      }).catch(err=>{
        this.tableLoading=false
        this.$message.error("导出失败")
      })
        //})
        .catch(() => {
        });
    },

    //监听
    closeprintTypeDialog(){
      this.saveCertificate={ //要保存的数据
            "businessCode": "",
            "memberId": 0,
            "memberVersion": 0,
            "certificateTypeCode":"",
            "operationTypeCode": 1,
            "operationTime": "",
            "operationCause": "",
            "cremationOldNo": "",
            "cremationNewNo": ""
          }
    },
    //载入火化证信息
      loadCremationCertificate(businessCode) {

        //查询火化证接口数据
        let postData = {
                businessCode,
                "dictTypeCodes": [
                "cremation_certificate_printing_operation_type"
              ]
            }

        Type['loadcremationcertificateprintingall'](postData).then(response => {
          //接收返回数据
          console.log('火化证',response.data)
          this.deadInfo=response.data;
          this.printHistory=response.data.printHistory
          this.printTypeVisible=true

          //调用打印接口
          //this.printCremationCertificate(response.data);
        })
      },
    //打印类型表单提交
    startPrint(formName){
      this.$refs[formName].validate((valid) => {
          if (valid) {
            //console.log()
            //打印
            this.$confirm('是否确认此操作?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                 this.realPrint(this.saveCertificate)
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消该操作'
                });
              });

          } else {
            console.log('error submit!!');
            return false;
          }
        });
    },
    realPrint(data){
      let postData = {
              "businessCode":this.deadInfo.funeralDead.businessCode,
              "memberId": this.deadInfo.familyMember.id,
              "memberVersion": this.deadInfo.familyMember.version,
              "operationTypeCode": data.operationTypeCode,
              "operationTime": "",
              "operationCause": data.operationCause,
              "cremationOldNo": this.deadInfo.cremation.cremationNo,
              "cremationNewNo": data.cremationNewNo,
              "cremationId":this.deadInfo.cremation.id,
              "cremationVersion":this.deadInfo.cremation.version
            }
            Type['savecremationcertificateprinting'](postData).then(res => {
              if(res.code===1){
                this.Print(res.data.funeralDead.businessCode);
              }else{
                this.$message.error(res.message)
              }
            })
    },
    Print(businessCode){
      let postData = {
             businessCode
           }
           Type['loadPrintCremationCertificate'](postData).then(response => {
             //接收返回数据
             let result = response.data;
             this.printTypeVisible=false
             console.log(result.cremationNo,result.cremationNo.substring(0,1),'ghdsghdsghdghdg')
             if(this.saveCertificate.operationTypeCode!==3){
               //调用打印接口
               this.printCremationCertificate(result);
             }else{
               //重打
               this.rePrintCremationCertificate(result);
             }
            //  if (result.cremationNo.substring(0,1)=="L") {
            //    //调用打印接口
            //    this.printCremationCertificate(result);
            //  }else
            //  {
            //    //调用打印接口
            //    this.rePrintCremationCertificate(result);
            //  }
           }).catch(error => {
             this.$message.error(error)
           })

    },

     //打印火化证
        printCremationCertificate(printData){
          let this_print=this;
          let LODOP =  getLodop();
          if (LODOP == null || !LODOP) {
            this_print.$.messager.alert('系统提示', '您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试');
            return;
          }
  console.log(printData,999)


      for (let key in printData) {
        printData[key] = printData[key]
          ? printData[key]
          : "　";
      }
          //当前业务时间
          let  businessCode=printData.businessCode;
          //火化证号
          let  cremationNo=printData.cremationNo;
          //业务编码
          let  firstParty="<h1>火　　化　　证　　明</h1>";
          //逝者姓名
          let  deadName= printData.deadName.replace(/\s*/g,'');
          //逝者性别
          let  deadGender=printData.deadGender;
          //逝者年龄
          let  deadAge="年龄："+printData.deadAge;
          //户口所在地
          //证件类型
          let certificateTypeCode=printData.certificateType;
          //逝者证件号码
          let certificateNo=printData.certificateNo;
          //火化时间
          let appointmentDate=printData.appointmentDate;

          //领证人
          let thisMemberName=printData.memberName.replace(/\s*/g,'');
          //组织机构
          let orgName=printData.orgName
          //机构电话
          let phone=printData.phone
          //生前住址
          let beforeDeathAddress=printData.beforeDeathAddress.replace(/\s*/g,'');
          let dataTable="　　逝者姓名: "+deadName+",　 性别:　"+deadGender+"  ,"+deadAge+",　 身份证类型:" +certificateTypeCode +
          　",证件号码:　"+certificateNo+",　逝者编号:　"+businessCode +
            ",生前地址: "+beforeDeathAddress+", 已于"+appointmentDate+"日在本单位火化。 ";

          let butoom1="发证单位(盖章):";
          let jingBan="经办人(签字):";
          let party=orgName;
          let gaizhang="（火化专用章）";
          let date = dataFormatetmd1(new Date());
          let tel= `　　 发证单位电话:${phone}`;
          //纸张
          //LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
          //设置字体
          //LODOP.ADD_PRINT_TEXT(50,220,650,25, "火化证明");
          LODOP.SET_PRINT_STYLE("FontSize", 12);

          //打印标题
          LODOP.ADD_PRINT_HTM(50,220,650,25,firstParty);
          //调用打印控件进行测试
          LODOP.ADD_PRINT_TEXT(140,250,650,28,"证明编号："+cremationNo);
          LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
          LODOP.SET_PRINT_STYLEA(0,"FontName","黑体");
          //打印协议
          LODOP.ADD_PRINT_TEXT(170,50,580,200,dataTable);
          // LODOP.ADD_PRINT_TEXT("\r\n");
          LODOP.ADD_PRINT_TEXT(260,72,250,60,"  特此证明。");
          LODOP.ADD_PRINT_TEXT(280,30,300,60,"  领证人: "+thisMemberName);
          //发证单位
          LODOP.ADD_PRINT_TEXT(300,470,650,50,party);
          //经办人
          LODOP.ADD_PRINT_TEXT(328,462,650,50,gaizhang);
           LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
          LODOP.ADD_PRINT_TEXT(370,460,650,50,date);
          LODOP.ADD_PRINT_TEXT(390,375,650,50,tel);
          // LODOP.ADD_PRINT_TEXT(425,500,650,50,date);
          // LODOP.ADD_PRINT_TEXT(445,380,650,50,tel);


          //打印边框
          //LODOP.ADD_PRINT_RECT(60,55,500,300,0,1);
          // LODOP.ADD_PRINT_TABLE(115,50,300,300,tableStr);
          //直接打印
          //打印预览
          LODOP.PREVIEW();
          //LODOP.PRINT();
          //LODOP.PRINT_DESIGN();
        },//补办火化证
        rePrintCremationCertificate(printData){
          let this_print=this;
          let LODOP =  getLodop();
          if (LODOP == null || !LODOP) {
            this_print.$.messager.alert('系统提示', '您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试');
            return;
          }
          for (let key in printData) {
            printData[key] = printData[key]
              ? printData[key]
              : "　";
          }
          //当前业务时间
          let  businessCode=printData.businessCode;
          //火化证号
          let  cremationNo=printData.cremationNo;
          //业务编码
          let  firstParty="<h1>补　办　火　化　证　明</h1>";
          //逝者姓名
          let  deadName= printData.deadName.replace(/\s*/g,'');
          //逝者性别
          let  deadGender=printData.deadGender;
          //逝者年龄
          let  deadAge="年龄："+printData.deadAge;
          //户口所在地
          //证件类型
          let certificateTypeCode=printData.certificateType;
          //逝者证件号码
          let certificateNo=printData.certificateNo;
          //火化时间
          let appointmentDate=printData.appointmentDate;
          //领证人
          let thisMemberName=printData.memberName;
           //组织机构
          let orgName=printData.orgName
          //机构电话
          let phone=printData.phone
          //生前住址
          let beforeDeathAddress=printData.beforeDeathAddress.replace(/\s*/g,'');
          let dataTable="　　逝者姓名: "+deadName+",　 性别:　"+deadGender+"  ,"+deadAge+",　 身份证类型:" +certificateTypeCode +
          　",证件号码:　"+certificateNo+",　逝者编号:　"+businessCode +
            ",生前地址: "+beforeDeathAddress+", 已于"+appointmentDate+"日在本单位火化。 ";

          let butoom1="发证单位(盖章):";
          let jingBan="经办人(签字):";
          let party=orgName;
          let gaizhang="（火化专用章）";
          let date = dataFormatetmd1(new Date());
          let tel=`　　 　发证单位电话:${phone}`;
          //纸张
          LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
          //设置字体
          //LODOP.ADD_PRINT_TEXT(50,220,650,25, "火化证明");
          LODOP.SET_PRINT_STYLE("FontSize", 12);

          //打印标题
          LODOP.ADD_PRINT_HTM(50,150,650,25,firstParty);
          LODOP.ADD_PRINT_BARCODE("4mm", "160mm", "28mm", "28mm", "QRCode", window.btoa(printData.businessCode));
          LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 2);
          LODOP.SET_PRINT_STYLEA(0, "DataCharset", "UTF-8");
          LODOP.ADD_PRINT_TEXT( "27mm", "140mm", 300,25,"业务编码：" + printData.businessCode);
          //调用打印控件进行测试
          LODOP.ADD_PRINT_TEXT(150,250,650,28,"证明编号："+cremationNo);
          LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
          LODOP.SET_PRINT_STYLEA(0,"FontName","黑体");
          //打印协议
          LODOP.ADD_PRINT_TEXT(180,50,650,200,dataTable);
          // LODOP.ADD_PRINT_TEXT("\r\n");
          LODOP.ADD_PRINT_TEXT(260,72,250,60,"  特此证明。");
          LODOP.ADD_PRINT_TEXT(280,30,300,60,"  领证人: "+thisMemberName);
          LODOP.ADD_PRINT_TEXT(350,30,650,100,`声明：此证明仅证明逝者在${orgName}火化，发生的任何法律后果与${orgName}无关\n`);
          // //发证单位
          // LODOP.ADD_PRINT_TEXT(310,462,650,50,party);
          // //经办人
          // LODOP.ADD_PRINT_TEXT(328,462,650,50,gaizhang);
          //  LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
          // LODOP.ADD_PRINT_TEXT(370,460,650,50,date);
          // LODOP.ADD_PRINT_TEXT(390,375,650,50,tel);
          //打印预览
          LODOP.PREVIEW();
        },
         //打印类型改变
    operationType(code){    //重打用原号码，发证重新填写
          let chongdaCode = 0,fazhengCode = 0,buzhengCode=0
          this.dictionary.cremation_certificate_printing_operation_type.forEach(item=>{
            if (item.dataText.indexOf("重打")>-1) {
              chongdaCode = item.dataCode
            }
            if (item.dataText.indexOf("发证")>-1) {
              fazhengCode = item.dataCode
            }
            if(item.dataText.indexOf("补证")>-1){
              buzhengCode=item.dataCode
            }
          })
          if (this.saveCertificate.operationTypeCode == fazhengCode){   //发证
            this.saveCertificate.cremationNewNo = ""
            this.deadInfo.familyMember.certificateTypeCode=fazhengCode
          }else if (this.saveCertificate.operationTypeCode == chongdaCode){  //重打
            this.saveCertificate.cremationNewNo = JSON.parse(JSON.stringify(this.deadInfo.cremation.cremationNo))
            this.deadInfo.familyMember.certificateTypeCode=chongdaCode
          }else if(this.saveCertificate.operationTypeCode == buzhengCode){//补证
            this.saveCertificate.cremationNewNo = ""
            this.deadInfo.familyMember.certificateTypeCode=buzhengCode
          }

    },
    //编辑
    editDead(businessCode){
      this.$refs.homeDialog.ReadData(businessCode)
    },
    //选择
    handleSelectionChange(val){
      console.log(val,'选择的')
    },
    //点击新增逝者
    addNewDead(){
      //console.log(this.homeDialogShow,'1')
      this.homeDialogShow=true
      //console.log(this.homeDialogShow,'2')
    },
    //删除逝者
    deleteDead(){

    },
    //默认初始值方法
    defaultValue() {
      //默认查询开始结束时间为当天
      this.ruleForm.appointmentDateStart = dataFormatetmd(new Date());
      this.ruleForm.appointmentDateEnd = dataFormatetmd(new Date());
    },
    onSubmit(value) {
      this.loading = true
      if (value) {
        this.pager.currentPage = 1;
      }
      var postData = {
        "appointmentDateStart": dataFormatetmd(new Date(this.ruleForm.appointmentDateStart)),
        "appointmentDateEnd": dataFormatetmd(new Date(this.ruleForm.appointmentDateEnd)),
        "deadName": this.ruleForm.deadName,
        "certificateNo": this.ruleForm.certificateNo,
        "remainsStateCode": this.ruleForm.remainsStateCode,
        "cremationTypeCode": this.ruleForm.cremationTypeCode,
        "areaCode": this.ruleForm.areaCode,
        "pageSize": this.pager.pageSize,
        "currentPage": this.pager.currentPage,
        "exportExcelFlag": 0,            //表示显示 1表示导出execl
        "orderField	": "",     //排序字段
        "orderType": "",        //排序顺序
        "cremationOrBuryType":"cremation"
      }
      //查询接口
      Type['loadCremationRecord'](postData).then(response => {
        const {data} = response;
        if (!data) {
          this.loading = false;
          this.$message('数据读取失败')
          return
        }
        this.tableData = data.list
        this.pager = data.pager
        this.loading = false
        //   //数据读取成功
      }).catch(error => {
        this.$message(error)
        this.loading = false
        this.tableData = []
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.ruleForm.appointmentDateStart = "";
      this.ruleForm.appointmentDateEnd = "";
      this.$refs["ruleForm"].resetFields();
      this.onSubmit();
    },
    // 初始页currentPage、初始每页数据数pageSize和数据data
    handleSizeChange: function (size) {
      this.pager.pageSize = size;
      this.onSubmit()
    },
    handleCurrentChange: function (currentPage) {
      this.pager.currentPage = currentPage;
      this.onSubmit()  //点击第几页
    },
    openExecl() {
      // window.location.href = "excel地址"
      if(this.tableData.length===0){
        this.$message({
          message:"暂无数据可导出",
          type:'warning'
        })
        return false
      }
       this.tableLoading=true
      var postData = {
        "appointmentDateStart": dataFormatetmd(new Date(this.ruleForm.appointmentDateStart)),
        "appointmentDateEnd": dataFormatetmd(new Date(this.ruleForm.appointmentDateEnd)),
        "deadName": this.ruleForm.deadName,
        "certificateNo": this.ruleForm.certificateNo,
        "remainsStateCode": this.ruleForm.remainsStateCode,
        "cremationTypeCode": this.ruleForm.cremationTypeCode,
        "areaCode": this.ruleForm.areaCode,
        "pageSize": this.pager.pageSize,
        "currentPage": this.pager.currentPage,
        "exportExcelFlag": 1,            //0表示显示 1表示导出execl
        "orderField	": "",     //排序字段
        "orderType": "",       //排序顺序
        'cremationOrBuryType':'cremation'
      }
      // 查询火化记录的接口
      download.exportExcel(Type["CremationRecordEXPEXC"], postData, "火化台账_" + download.getDateTime() + ".xlsx").then(res=>{
        //console.log(res,'导出Excelpromise')
        if(res==='成功'){
          this.tableLoading=false
        }else{
          this.tableLoading=false
          this.$message.error("导出失败")
        }
      }).catch(err=>{
        console.log(err,'失败了啊')
        this.tableLoading=false
          this.$message.error("导出失败")
      })
    },
  }
}
</script>

<style scoped>

.w150 {
  width: 150px;
}
.print_dialog /deep/ .el-dialog .el-dialog__body{
    background: #fff;
    padding:0;
}
.print_dialog /deep/ .el-dialog .el-dialog__body{
    background: #F6F9FF;
    height: 400px;
    overflow-y: scroll;
    padding:0
}
</style>
